function Solve(params)
{
    var firstRow = params[0].split(' ').map(Number),
        commands = new Array(firstRow[0]);

    for (var i = 0; i < commands.length; i++)
    {
        commands[i] = params[i + 1].split(' ');
    }

    var field = new Array(firstRow[0]);

    for (var i = 0; i < field.length; i++)
    {
        field[i] = new Array(firstRow[1]);
    }

    for (var rows = 0; rows < field.length; rows++)
    {
        stepper = Math.pow(2, rows);
        for (var columns = 0; columns < field[0].length; columns++)
        {
            field[rows][columns] = stepper;
            stepper++;
        }
    }

    var sum = 0;
    var position = [0, 0];

    for (var rows = 0; rows < commands.length; rows++)
    {
        for (var columns = 0; columns < commands[0].length; columns++)
        {
            if (position[0] >= field.length || position[0] <= -1 || position[1] >= field[0].length || position[1] <= -1)
            {
                return 'successed with ' + sum;
            }

            if (field[position[0]][position[1]] === 0)
            {
                return 'failed at (' + position[0] + ', ' + position[1] + ')';
            }
            else
            {
                sum += field[position[0]][position[1]];
                field[position[0]][position[1]] = 0;
            }

            if (commands[position[0]][position[1]] === 'dr')
            {
                position[0]++;
                position[1]++;
            }
            else if (commands[position[0]][position[1]] === 'ur')
            {
                position[0]--;
                position[1]++;
            }
            else if (commands[position[0]][position[1]] === 'ul')
            {
                position[0]--;
                position[1]--;
            }
            else if (commands[position[0]][position[1]] === 'dl')
            {
                position[0]++;
                position[1]--;
            }
            else
            {
                console.log("Error with the commands check");
            }
        }
    }
}

var input = [
    '3 5',
    'dr dl dl ur ul',
    'dr dr ul ul ur',
    'dl dr ur dl ur'
];

console.log(Solve(input));